
#include "stdafx.h"
#include "WicPalette.h"

CWicPalette::CWicPalette()
{
    m_pIWICPalette = NULL;
    g_theImagingFactory->CreatePalette(&m_pIWICPalette);
}

CWicPalette::~CWicPalette()
{
    if(m_pIWICPalette)
    {
        m_pIWICPalette->Release();
    }
    m_pIWICPalette = NULL;
}

CWicPalette::CWicPalette(CWicPalette const & objPalette)
{
    m_pIWICPalette = objPalette.m_pIWICPalette;
    m_pIWICPalette->AddRef();
}

CWicPalette& CWicPalette::operator=(CWicPalette const & objPalette)
{
    if(m_pIWICPalette)
    {
        m_pIWICPalette->Release();
    }
    m_pIWICPalette = objPalette.m_pIWICPalette;
    m_pIWICPalette->AddRef();
    return *this;
}

HRESULT STDMETHODCALLTYPE CWicPalette::InitializePredefined( 
        /* [in] */ WICBitmapPaletteType ePaletteType,
        /* [in] */ BOOL fAddTransparentColor)
{
    g_hrLast = m_pIWICPalette->InitializePredefined(ePaletteType, fAddTransparentColor);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::InitializeCustom( 
        /* [size_is][in] */ __RPC__in_ecount_full(cCount) WICColor *pColors,
        /* [in] */ UINT cCount)
{
    g_hrLast = m_pIWICPalette->InitializeCustom(pColors, cCount);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::InitializeFromBitmap( 
        /* [in] */ __RPC__in_opt CWicBitmapSource *pISurface,
        /* [in] */ UINT cCount,
        /* [in] */ BOOL fAddTransparentColor)
{
    g_hrLast = m_pIWICPalette->InitializeFromBitmap(pISurface->GetPtr(), cCount, fAddTransparentColor);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::InitializeFromPalette( 
        /* [in] */ __RPC__in_opt CWicPalette *pIPalette)
{
    g_hrLast = m_pIWICPalette->InitializeFromPalette(pIPalette->m_pIWICPalette);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::GetType( 
        /* [out] */ __RPC__out WICBitmapPaletteType *pePaletteType)
{
    g_hrLast = m_pIWICPalette->GetType(pePaletteType);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::GetColorCount( 
        /* [out] */ __RPC__out UINT *pcCount)
{
    g_hrLast = m_pIWICPalette->GetColorCount(pcCount);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::GetColors( 
        /* [in] */ UINT cCount,
        /* [size_is][out] */ __RPC__out_ecount_full(cCount) WICColor *pColors,
        /* [out] */ __RPC__out UINT *pcActualColors)
{
    g_hrLast = m_pIWICPalette->GetColors(cCount, pColors, pcActualColors);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::IsBlackWhite( 
        /* [out] */ __RPC__out BOOL *pfIsBlackWhite)
{
    g_hrLast = m_pIWICPalette->IsBlackWhite(pfIsBlackWhite);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::IsGrayscale( 
        /* [out] */ __RPC__out BOOL *pfIsGrayscale)
{
    g_hrLast = m_pIWICPalette->IsGrayscale(pfIsGrayscale);
    return g_hrLast;
}

HRESULT STDMETHODCALLTYPE CWicPalette::HasAlpha( 
        /* [out] */ __RPC__out BOOL *pfHasAlpha)
{
    g_hrLast = m_pIWICPalette->HasAlpha(pfHasAlpha);
    return g_hrLast;
}

IWICPalette* CWicPalette::GetPtr()
{
    return m_pIWICPalette;
}

